<?php
class Ext_Model_Navigation extends Ext_Db_Table
{
	protected $_name = "sys_menu";
	protected $_sequence = "sys_menu_seq";
	protected $_primary = "menu_id";
	
	public function fetchChildren( $parent )
	{
		$row = $this->fetchAll ( 
			$this->select()
			->where('parent_id = ?', $parent->menu_id ) 
		);
		return $row;
	}
	
	public function getTree() 
	{
		$rowset = $this->fetchAll( "locked = 'F' AND parent_id = 0 AND type='admin'" );
		$menu = array();
		foreach( $rowset as $row ) {
			$menu[$row->menu_id]['hdr'] = $row;
			$menu[$row->menu_id]['children'] = $this->fetchChildren( $row );
		}
		return $menu;
	}	
}